public class MyQueue {

    static class ListNode{
        public int val;
        public ListNode next;
        public ListNode prev;
        public ListNode(int val){
            this.val=val;
        }
    }
    public ListNode first;
    public ListNode last;
    public int usedsize;

    public void offer(int val){
        ListNode node =new ListNode(val);
        if(first==null){
            first=last=node;
            usedsize++;
            return;
        }
        last.next=node;
        node.prev=last;
        last=node;
        usedsize++;
    }

    public boolean empty(){
        return usedsize==0;
    }

    public int poll(){
        if(first==null){
            throw new MyQueueException("poll:队列为空，无法出队列！！！");
        }
        int val=first.val;
        first=first.next;
        if(first==null){

        }else {
            first.prev=null;
        }
        usedsize--;
        return val;
    }

    public void dispaly(){
        ListNode cur=first;
        while(cur!=null){
            System.out.print(cur.val+" ");
            cur=cur.next;
        }
        System.out.println();
    }

    public int peek(){
        if(first==null){
            throw new MyQueueException("peek:队列为空!!!");
        }
        return first.val;
    }
}
